package cn.aib.acl.service.impl;

import cn.aib.acl.entity.User;
import cn.aib.acl.entity.UserRole;
import cn.aib.acl.mapper.UserMapper;
import cn.aib.acl.service.UserRoleService;
import cn.aib.acl.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-01-12
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private UserRoleService userRoleService;
    @Override
    public User selectByUsername(String username) {
        return baseMapper.selectOne(new QueryWrapper<User>().eq("username", username));
    }

    @Override
    public void removeByUserId(String userId) {
        //删除用户角色表
        QueryWrapper<UserRole> userRoleWrapper = new QueryWrapper<>();

        userRoleWrapper.eq("user_id", userId);

        userRoleService.remove(userRoleWrapper);

        //删除用户表
        baseMapper.deleteById(userId);
    }
}
